package com.zhao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class AppCommandLineRunner implements CommandLineRunner {

	@Autowired
	TaskExecutor taskExecutor;
	
	@Autowired
	RestTemplate restTemplate;
	
	public static final String root="https://www.vmoney.cn/#/"; 
	
	@Override
	public void run(String... args) throws Exception {
//		String result=restTemplate.getForObject(root, String.class);
//		CloseableHttpClient httpClient = HttpClients.createDefault();
//		HttpUriRequest get = RequestBuilder.get().setUri(root).build();
//		ResponseHandler<String> rh = new ResponseHandler<String>() {
//			@Override
//			public String handleResponse(final HttpResponse response) throws IOException {
//				StatusLine statusLine = response.getStatusLine();
//				HttpEntity entity = response.getEntity();
//				if (statusLine.getStatusCode() >= 300) {
//					throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
//				}
//				if (entity == null) {
//					throw new ClientProtocolException("Response contains no content");
//				}
//				BufferedReader reader = null;
//				String result = null;
//				StringBuffer sbf = new StringBuffer();
//				reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
//				String strRead = null;
//				while ((strRead = reader.readLine()) != null) {
//					sbf.append(strRead);
//					sbf.append("\r\n");
//				}
//				reader.close();
//				result = sbf.toString();
//				return result;
//			}
//		};
//		String result = null;
//		try {
//			result = httpClient.execute(get, rh);
//		} catch (ClientProtocolException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		System.out.println(result);
		//		new AsyncCrawlerTask();
	}
}
